﻿using Ninject.Modules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ninject.Extensions.Conventions;
using PAP.Application.Core;

namespace PAP.Services.Commands
{
    public class ModuleActivation : NinjectModule
    {
        public override void Load()
        {
            const string commandHandlersAssemblyPattern = "PAP.Application.CommandHandlers.dll";
            Kernel.Bind(x =>
            {
                x.FromAssembliesMatching(commandHandlersAssemblyPattern)
                    .SelectAllClasses()
                    .InheritedFrom(typeof(ICommandHandler<>))
                    .BindSingleInterface();
            });
            Kernel.Bind(x =>
            {
                x.FromAssembliesMatching(commandHandlersAssemblyPattern)
                    .SelectAllClasses()
                    .InheritedFrom(typeof(ICommandHandler<,>))
                    .BindSingleInterface();
            });
        }
    }
}
